package com.wskeee.ec.components
{
	import flash.display.DisplayObject;
	import flash.geom.Rectangle;
	
	import com.wskeee.ec.components.skin.HScrollBarSkin;

	public class HScrollBar extends ScrollBarBase
	{
		public function HScrollBar()
		{
			super(HORIZONTAL);
			width = 100;
			height = 16;
		}
		
		//========================= override ====================
		override public function set target(value:DisplayObject):void
		{
			super.target = value;
			if(target && !viewarea)
			{
				var rect:Rectangle = value.scrollRect ? value.scrollRect : new Rectangle(0,0,width,value.height);
				viewarea = rect;
			}
		}
		
		override protected function onChange():void
		{
			super.onChange();
			if(target && viewarea)
			{
				var sr:Rectangle = target.scrollRect;
				if(!sr)sr = new Rectangle();
				var dx:Number = (scrollPosition/maxScrollPosition)*(maxScrollPosition - viewarea.width);
				target.scrollRect = new Rectangle(dx,sr.y,viewarea.width,viewarea.height);
			}
		}
		//========================= end =========================
		
		//========================= get & set ===================
		//---------------------
		//override skinableComponent
		//---------------------
		override public function get DefaultSkinDrawer():Class
		{
			return HScrollBarSkin;
		}
		//========================= end =========================
	}
}